package org.jederik.studip.android.view;

import org.jederik.android.provider.StudIP;
import org.jederik.android.provider.StudIP.Schedules;
import org.jederik.studip.android.R;
import org.jederik.studip.android.view.tools.ResourceActivity;
import org.jederik.studip.android.view.tools.FormatHelper;

import android.database.Cursor;
import android.widget.TextView;

/**
 * Zeigt einen Termin im Detail an
 * @author Jann-Frederik Laß
 *
 */
public class ViewSchedule extends ResourceActivity {

	@Override
	public void initView() {
		// Layout laden:
		setContentView(R.layout.view_schedule);
	}

	@Override
	public void showData(Cursor cursor) {
		
		if (cursor == null || !cursor.moveToFirst()) {
			return;
		}
		
		// Titel in Titelzeile einfügen:
		TextView title = (TextView) findViewById(R.id.title);
		title.setText(cursor.getString(cursor.getColumnIndex(Schedules.TITLE)));
		
		// Bereich in Bereich-Zeile einfügen:
		TextView range = (TextView) findViewById(R.id.range);
		range.setText(cursor.getString(cursor.getColumnIndex(Schedules.RANGE)));
		
		// Formatiertes Startdatum in Startzeile einfügen:
		TextView start = (TextView) findViewById(R.id.start);
		String timestamp = cursor.getString(cursor.getColumnIndex(Schedules.START));
		if (timestamp==null) timestamp = "0";
		start.setText(FormatHelper.formatDate(Integer.parseInt(timestamp)));
		
		// Formatiertes Enddatum in Endzeile einfügen:
		TextView end = (TextView) findViewById(R.id.end);
		timestamp = cursor.getString(cursor.getColumnIndex(Schedules.END));
		if (timestamp==null) timestamp = "0";
		end.setText(FormatHelper.formatDate(Integer.parseInt(timestamp)));
		
		// Beschreibung in Beschreibungsfeld einfügen
		TextView description = (TextView) findViewById(R.id.description);
		description.setText(cursor.getString(cursor.getColumnIndex(Schedules.DESCRIPTION)));
		
	}

	@Override
	public String getType() {
		return StudIP.TYPE_SCHEDULE;
	}

	@Override
	public String getId() {
		return getIntent().getData().getLastPathSegment();
	}

	@Override
	public boolean canBeVisited() {
		return true;
	}
}
